<template>
    <div ref="wrapper">
        <div>
            <slot></slot>
        </div>
    </div>
</template>

<script>
    import BScroll from 'better-scroll';

    export default {
        name: "Scroll",
        props: {
            probeType: {
                type: Number,
                default: 1
            },
            pullUpLoad: {
                type: Boolean,
                default: false
            }
        },
        data() {
            return {
                scroll: null
            }
        },
        mounted() {
            this.scroll = new BScroll(this.$refs.wrapper, {
                probeType: this.probeType, //实时侦测
                pullUpLoad: this.pullUpLoad, //上拉加载
                click: true, //打开点击事件
            })

            this.scroll.on('scroll', position => {
                this.$emit('scroll',position)
            })

            this.scroll.on('pullingUp', () => {
                this.$emit('pullingUp');
            })
        },
        methods: {
            scrollTo(x, y, ms) {
                this.scroll && this.scroll.scrollTo(x, y, ms);
            },
            finishPullUp() {
                this.scroll && this.scroll.finishPullUp();
            },
            refresh() {
                this.scroll && this.scroll.refresh();
            },
            getScrollY() {
                return this.scroll ? this.scroll.y : 0;
            }
        }
    }
</script>

<style scoped>
</style>